package com.gs.synedocket.dialog;


import android.content.Context;

import com.gs.synedocket.R;

public class LoadingDialogUtils {
    private static volatile LoadingDialogUtils instance;

    private LoadingDialogUtils() {
    }

    public static LoadingDialogUtils getInstance() {
        if (instance == null) {
            synchronized (LoadingDialogUtils.class) {
                if (instance == null) {
                    instance = new LoadingDialogUtils();
                }
            }
        }
        return instance;
    }

    private static ToastDialog dialog;

    public void setCancelable(boolean flag) {
        dialog.setCancelable(flag);
    }

    public boolean isShowing(){
        return dialog.isShowing();
    }

    public void showLoading(Context mContext, String msg) {
        if (dialog != null && isShowing()) {
            dialog.dismiss();
            dialog = null;
        }
        dialog = new ToastDialog(mContext).setMessage(msg).setIco(R.mipmap.loading);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(true);
        dialog.show();
    }

    public void showLoading(Context mContext) {
        if (dialog != null && isShowing()) {
            dialog.dismiss();
            dialog = null;
        }
        dialog = new ToastDialog(mContext).setMessage(mContext.getString(R.string.loading)).setIco(R.mipmap.loading);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(true);
        dialog.show();
    }

    public void dismiss() {
        if (dialog != null) {
            dialog.dismiss();
        }
    }
}
